Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test that on- and addEventListener callbacks fire on passthrough #117

Merged
merged 1 commit into from
Oct 5, 2015

Conversation

bantic
Copy link
Member

@bantic bantic commented Oct 2, 2015

This PR changes:

  • restores the native window.XMLHttpRequest correctly in "passthrough" tests
  • fixes an incorrect call to FakeXHR#dispatch that caused event listeners added using addEventListener from firing on passed-through requests

In the passthrough tests, there are a few places where pretender._nativeXMLHttpRequest is changed in order to facilitate testing, but Pretender sets the window's XMLHttpRequest to this._nativeXMLHttpRequest in #shutdown. This resulted in window.XMLHttpRequest getting incorrectly permanently changed to the stub tesXHR method when those tests call pretender.shutdown in teardown.

FakeXMLHttpRequest's dispatchEvent method
must be called with the event (which must have a type key) instead of
(eventName, event). When called with the eventName string as the first argument, the fake XHR never locates the addEventListener-added listeners and so never calls them. This PR fixes the call to dispatchEvent to have the correct parameter and adds tests that callbacks added using both methods will be called.

This change ensures that native window.XMLHttpRequest is restored
in passthrough tests, even after pretender's reference to
`_nativeXMLHttpRequest` is changed in the tests.

Also adds tests that listeners added with `addEventListener` are called
on a passed-through xhr. FakeXMLHttpRequest's `dispatchEvent` method
must be called with the event (which must have a `type` key) instead of
`(eventName, event)`.
trek added a commit that referenced this pull request Oct 5, 2015
test that `on`- and `addEventListener` callbacks fire on passthrough
@trek trek merged commit 5985f27 into pretenderjs:master Oct 5, 2015
@bantic bantic deleted the fix-passthrough-event-listeners branch October 5, 2015 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants